package com.xidian.zhiancloud.service.warnforecast.basicsset;

import com.xidian.zhiancloud.dao.WarnLevelSetMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.WarnLevelSet;
import com.xidian.zhiancloud.model.WarnLevelSetExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Service
@Transactional
public class WarnLevelSetService {

    @Autowired
    private WarnLevelSetMapper warnLevelSetMapper;

    public List<WarnLevelSet> getList(int current, int size) {
        WarnLevelSetExample exampleGenerator = new WarnLevelSetExample();
        return warnLevelSetMapper.selectByExampleWithRowbounds(exampleGenerator, new RowBounds(current, size));
    }

    public void update(WarnLevelSet warnLevelSet) {

        WarnLevelSetExample exampleGenerator = new WarnLevelSetExample();
        WarnLevelSetExample.Criteria criteria = exampleGenerator.createCriteria();
        criteria.andIdEqualTo(warnLevelSet.getId());
        WarnLevelSet warn = new WarnLevelSet();
        warn.setJobId(warnLevelSet.getJobId());
        int count = warnLevelSetMapper.updateByExampleSelective(warn,exampleGenerator);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
}
